package com.asset.dispoal.file.bank.domain.service.command;

import com.asset.dispoal.file.bank.domain.db.mapper.FileBankMapper;
import com.asset.dispoal.file.bank.dto.FileBankLevelAmountResponse;
import com.asset.dispoal.file.replyDetail.dto.FileReplyTypeData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommandNoParam;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.math.BigDecimal;

@Component
public class FileBankQueryLevelAmountCommand implements BaseCommandNoParam<Result> {

    @Autowired
    private FileBankMapper fileBankMapper;

    public Result execute() {
        FileBankLevelAmountResponse response = new FileBankLevelAmountResponse();
        response.setDataList(fileBankMapper.queryByLevelAmount());
        response.setAmount(response.getDataList().stream().map(FileReplyTypeData::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
        return Result.ok(response);
    }
}
